<template>
	<view class="UserSet">
		<view class="UserSet-main">
			<view
				class="UserSet-main-item"
				:key="index"
				v-for="(item, index) in functionTypeList"
				:class="{
					line: item.isLine
				}"
				@click.prevent="clickJump(item)"
			>
				<view class="UserSet-main-item-left">
					<image :src="item.icon" />
				</view>

				<view class="UserSet-main-item-center">
					{{ item.label }}
				</view>

				<view class="UserSet-main-item-right">
					<image src="@/static/images/my/icon_more.png" />
				</view>
			</view>

			<view class="UserSet-main-footer">
				<button @click.stop="logOut">退出</button>
			</view>
		</view>
	</view>
</template>

<script>
import { mapMutations } from 'vuex';
import { defaultImageUrl } from '@/utils';

const functionTypeList = Object.freeze([
	{
		isLine: true,
		label: '个人信息',
		path: '/setupPage/UserInfo',
		icon: require('@/static/images/user/icon_setting_i.png')
	},

	// #ifdef APP-PLUS
	{
		label: '接收消息通知',
		icon: require('@/static/images/user/icon_setting_information.png')
	},
	{
		label: '清理缓存',
		icon: require('@/static/images/user/icon_setting_i.png')
	},
	// #endif
	{
		label: '用户协议',
		icon: require('@/static/images/user/icon_setting_yhxy.png'),
		callBack: function () {
			const webView = `${defaultImageUrl}webView/Commitment.html`;
			const url = `/tandianPage/CommonWebView?webView=${webView}`;

			uni.navigateTo({
				url
			});
		}
	},
	{
		label: '隐私政策',
		icon: require('@/static/images/user/icon_setting_yszc.png'),
		callBack: function () {
			const webView = `${defaultImageUrl}webView/PlatformPrivacyAgreement.html`;
			const url = `/tandianPage/CommonWebView?webView=${webView}`;

			uni.navigateTo({
				url
			});
		}
	},
	{
		label: '关于联联探客',
		path: '/setupPage/About',
		icon: require('@/static/images/user/icon_setting_about.png')
	}
]);

export default {
	name: 'UserSet',

	data() {
		return {
			functionTypeList
		};
	},

	onLoad() {},

	methods: {
		...mapMutations(['changeToken', 'changeUserInfo']),

		logOut() {
			uni.showModal({
				title: '提示',
				content: '是否退出登录',
				success: ({ confirm }) => {
					if (!confirm) {
						return;
					}

					uni.redirectTo({
						url: '/authorizePage/WechatAuthorize',
						success: () => {
							this.changeToken();
							this.changeUserInfo({});
						}
					});
				}
			});
		},

		clickJump(params) {
			const { path, callBack } = params;

			callBack && callBack.call(this);

			path &&
				uni.navigateTo({
					url: path
				});
		}
	}
};
</script>

<style lang="scss" scoped>
@import '@/style/common.scss';

.UserSet {
	&-main {
		padding: 20rpx 32rpx 32rpx;
		background: #fff;

		&-item {
			height: 100rpx;

			display: flex;
			align-items: center;

			font-size: 28rpx;

			&.line {
				margin-bottom: 22rpx;
				padding-bottom: 24rpx;
				border-bottom: 2rpx solid #eee;
			}

			> view {
				display: flex;
				align-items: center;
			}

			image {
				width: 32rpx;
				height: 32rpx;
			}

			&-center {
				flex: 1;

				color: #333;
				padding-left: 12rpx;
			}

			&-right {
				color: #999;
			}
		}

		&-footer {
			margin-top: 40rpx;

			button {
				@include Db_commonButton(80rpx, 24rpx);

				color: #666;
				background: #f6f6f6;

				&:active {
					background: rgba(246, 246, 246, 0.7);
				}
			}
		}
	}
}
</style>
